﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RAMED
{
    public partial class LOT : Form
    {
        public BindingList<Bordereau> bordereauRecherche = new BindingList<Bordereau>();
         public LOT()
        {
            InitializeComponent();
            //dataGridViewlot.DataSource = bordereauRecherche;
            remplirDataGridView();
        }

        private void btnajouterbordereau_Click(object sender, EventArgs e)
        {
           Bordereau_Form bor = new Bordereau_Form();
           bor.lot = this;
           bor.Show();
           
            
        }
        public void mettreAjouterFormGridViewlot() 
        {
             dataGridViewlot.DataSource = null;
             remplirDataGridView();
             dataGridViewlot.Update();
             dataGridViewlot.Refresh(); 
        }

        private void btnAjouterlot_Click(object sender, EventArgs e)
        {

            if (ValidateChildren(ValidationConstraints.Enabled))
            {
                RAMEDEntities1 Context = SingletonContext.GetContext();
                Lot Lotajoute = new Lot();
                Lotajoute.date_traitement = dateTimePickerlot.Value;
                Lotajoute.num_de_lot = utitlitaire.CasterString(txtnumdelot.Text);
                Lotajoute.total_do_lot = utitlitaire.CasterString(txttotaldelot.Text);
                Context.Lots.AddObject(Lotajoute);
                foreach (Bordereau bordereau in bordereauRecherche)
                    Lotajoute.Bordereaux.Add(bordereau);
                Context.SaveChanges();

                this.Dispose();
            }
        }

        private void txtdatedetretement_TextChanged(object sender, EventArgs e)
        {

        }

        private void LOT_Load(object sender, EventArgs e)
        {

        }

        private void dateTimePickerlot_ValueChanged(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        private void btnrecherche_Click(object sender, EventArgs e)
        {
            RecherchelotForm lot = new RecherchelotForm();

            lot.Show();
        }

        private void btnbord_Click(object sender, EventArgs e)
        {
            Bordereau_Form bor = new Bordereau_Form();
            bor.Show();
        }

        private void remplirDataGridView()
        {
            dataGridViewlot.AutoGenerateColumns = false;
            dataGridViewlot.ColumnCount = 3;
            dataGridViewlot.Columns[0].HeaderText = "Type";
            dataGridViewlot.Columns[0].DataPropertyName = "type_bordereau";

            dataGridViewlot.Columns[1].HeaderText = "ANNEXE ADMINISTRATIVE";
            dataGridViewlot.Columns[1].DataPropertyName = "Annexe_administratif";

            dataGridViewlot.Columns[2].HeaderText = "Nombre des Cartes";
            dataGridViewlot.Columns[2].DataPropertyName = "Nombre_de_carte";


            dataGridViewlot.DataSource = bordereauRecherche;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Recherche_correction rc = new Recherche_correction();
            rc.Show();
        }

        private void txtnumdelot_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderNombre("Saisissez un nomero valide", txtnumdelot, e, errorProvider1);
        }

        private void txttotaldelot_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderNombre("Saisissez un total valide", txttotaldelot, e, errorProvider1);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void Button21_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void modifBordButton_Click(object sender, EventArgs e)
        {

        }

    }
}
